import request from '@/utils/request';
import { setToken } from '@/utils/token-util';

/**
 * 账号密码登录
 */
export async function checkAccountLogin(params) {
  const res = await request.post('/login/checkAccountLogin', params);
  if (res.data.code === 1) {
    setToken(res.data.data?.token, params.remember);
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 获取验证码
 */
export async function getCaptcha() {
  const res = await request.get('/login/getCaptcha');
  if (res.data.code === 1 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}
